<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<!-- <th:block th:include="include :: datetimepicker-css" /> -->
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-snpub-add">
	<div class="form-group">
			<label class="col-sm-3 control-label">签到标题：</label>
			<div class="col-sm-8">
				<input id="title" name="title" class="form-control" type="text">
			</div>
		</div>
			<div class="form-group">
			<label class="col-sm-3 control-label">是否指定签到对象（默认on指定）：</label>
			<div class="col-sm-8">
				<!-- <input id="hasobj" name="hasobj" class="form-control" type="text"> -->
				<div class="onoffswitch">
					<input type="checkbox" checked="true" class="onoffswitch-checkbox" id="hasobj" name="hasobj">
					<label class="onoffswitch-label" for="hasobj">
						<span class="onoffswitch-switch"></span>
						<span class="onoffswitch-inner"></span>
					</label>
				</div>
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">签到对象：</label>
			<div class="col-sm-8">
				<input id="snobj" name="snobj" class="form-control" type="text">
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">签到形式：</label>
			<div class="col-sm-8">
				<input id="sntype" name="sntype" class="form-control" type="text" value="普通签到">
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">是否手动结束（默认on指定时间）：</label>
			<div class="col-sm-8">
				<!-- <input id="hasendtime" name="hasendtime" class="form-control" type="text"> -->
				<div class="onoffswitch">
					<input type="checkbox" checked="true" class="onoffswitch-checkbox" id="hasendtime" name="hasendtime">
					<label class="onoffswitch-label" for="hasendtime">
						<span class="onoffswitch-switch"></span>
						<span class="onoffswitch-inner"></span>
					</label>
				</div>
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">签到开始时间：</label>
			<div class="col-sm-8 input-group date">
				<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				<input id="snstarttime" name="snstarttime" class="form-control" type="text" placeholder="yyyy-MM-dd HH:mm">
			</div>
		</div>
	
			<div class="form-group">
			<label class="col-sm-3 control-label">签到结束时间：</label>
			<div class="col-sm-8 input-group date">
				<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				<input id="snendtime" name="snendtime" class="form-control" type="text" placeholder="yyyy-MM-dd HH:mm">
				<!-- <input id="snendtime" name="snendtime" class="form-control time-input" type="text"> -->
			</div>
		</div>
	
	</form>
</div>
<div th:include="include::footer"></div>
<th:block th:include="include :: jquerydateFormat-js" />
<script type="text/javascript">
	var prefix = ctx + "signin/snpub";
	$("#form-snpub-add").validate({
		onkeyup: false,
		rules:{
			xxxx:{
				required:true,
			},
		}
	});

	function submitHandler() {
		if ($.validate.form()) {
			$.operate.save(prefix + "/addDo", $('#form-snpub-add').serialize());
		}
	}
	function now(){
		return $.format.date(new Date(),"yyyy-MM-dd HH:mm");
	}
	$(function(){
		$("#title").val("签到");
		/* $("#snstarttime").datetimepicker(); */
		layui.use('laydate', function(){
     		  var laydate = layui.laydate;
     		 var startDate = laydate.render({ 
        		    elem: '#snstarttime',
        		    type: 'datetime',
        		    //max: $('#snendtime').val(),
    		        theme: 'molv',
    		        trigger: 'click',
    		        value: new Date(),//初始值
    		        done: function(value, date) {
    		            // 结束时间大于开始时间
    		            if (value !== '') {
    		                endDate.config.min.year = date.year;
    		                endDate.config.min.month = date.month - 1;
    		                endDate.config.min.date = date.date;
    		                endDate.config.min.hours = date.hours;
    		                endDate.config.min.minutes = date.minutes+1;
    		                endDate.config.min.seconds = date.seconds;
    		                $("#title").val($.format.date(new Date(value),"yyyy-MM-dd HH:mm")+$("#title").val());
    		            } else {
    		                endDate.config.min.year = '';
    		                endDate.config.min.month = '';
    		                endDate.config.min.date = '';
    		                endDate.config.min.hours = '';
    		                endDate.config.min.minutes = '';
    		                endDate.config.min.seconds = '';
    		            }
    		        }
        		  });
     		var endDate = laydate.render({ 
    		    elem: '#snendtime',
    		    type: 'datetime',
    		    min: $('#snstarttime').val(),
		        theme: 'molv',
		        trigger: 'click',
		        value: new Date(),
		        done: function(value, date) {
		            // 开始时间小于结束时间
		            if (value !== '') {
		                startDate.config.max.year = date.year;
		                startDate.config.max.month = date.month - 1;
		                startDate.config.max.date = date.date;
		                startDate.config.min.hours = date.hours;
		                startDate.config.min.minutes = date.minutes-1;
		                startDate.config.min.seconds = date.seconds;
		            } else {
		                startDate.config.max.year = '';
		                startDate.config.max.month = '';
		                startDate.config.max.date = '';
		                startDate.config.min.hours = '';
		                startDate.config.min.minutes = '';
		                startDate.config.min.seconds = '';
		            }
		        }
    		  });
     		
		})
		 $("#hasobj").on('click',function (e) {
	            var onswitch= this.checked;
	            if (onswitch)
	            {
	            	$("#snobj").parents(".form-group").show();
	            }
	            else
	            {
	            	$("#snobj").parents(".form-group").hide();
	            }
	        });
		$("#hasendtime").on('click',function (e) {
            var onswitch= this.checked;
            if (onswitch)
            {
            	$("#snendtime").parents(".form-group").show();
            	$('#snendtime').val(now());
            }
            else
            {
            	$("#snendtime").parents(".form-group").hide();
            	$('#snendtime').val("");
            }
        });
	})
</script>
</body>
</html>
